/**
 * WxSetting
 * @authors 杨兴洲（of2502）
 * @date    2017/5/23 0023 21:05
 * @version 1.0
 * @last-modify  杨兴洲（of2502）
 */

import React, { Component } from 'react';
import { Map } from 'immutable';
import { Relax } from 'iflux2';
import BindWaitingModal from '../../main/component/BindWaitingModal';
import { Modal } from 'antd';
import GaUtil from 'util/ga-util';
const confirm = Modal.confirm;

@Relax
class WxSetting extends Component {
  static defaultProps = {
    userInfo: Map(),
    authUrl: 'javascript:;'
  };

  constructor(props) {
    super(props);
    this.state = {
      visible: false
    };
  }

  render() {
    const { nick_name, alias, service_type_info = {}, verify_type_info = {} } = this.props.userInfo.toJS();
    return (
      <div className="WxSetting">
        <dl>
          <dt>公众微信号：</dt>
          <dd style={{ display: alias ? 'inline-block' : 'none' }}>{alias}</dd>
          <dd style={{ display: alias ? 'none' : 'inline-block' }}>
            您的公众号暂未设置微信号，可设置并重新授权
            <a style={{ marginLeft: '0.5em' }} href="https://mp.weixin.qq.com" target="_blank">去设置</a>
          </dd>
          <dd>
            <a className="btn" href="javascript:void(0);" onClick={this.showConfirm}>解除绑定</a>
            {/*<a style={{marginLeft: "0.5em"}} href="http://help.qianmi.com/hc/kb/article/1055903/" target="_blank">?</a>*/}
          </dd>
        </dl>
        <dl>
          <dt>公众号昵称：</dt>
          <dd>{nick_name}</dd>
        </dl>
        <dl>
          <dt>微信账号类型：</dt>
          <dd>{verify_type_info.name + service_type_info.name || ''}</dd>
        </dl>
        <dl>
          <dt />
          <dd className="tips">
            如果在使用中发现接口有异常，请点此
            <a href="javascript:" style={{ marginLeft: '0.5em' }} onClick={this.goToAuth}>重新授权</a>
          </dd>
        </dl>
        <BindWaitingModal ref={modal => (this.modal = modal)} authUrl={this.props.authUrl} />
      </div>
    );
  }

  goToAuth = () => {
    // this.modal.goToAuth();
    GaUtil.addEvent({ eventAction: '重新授权', eventLabel: '公众号设置' });
    const key = location.hash.split('?')[1]; // 增加key.方便控制台获取角色
    location.href = '/bind.html#/?' + key;
  };

  showConfirm = () => {
    confirm({
      title: '确定解除绑定？',
      content: '解绑公众号，商城中所有粉丝数据将会丢失，请谨慎操作!!!',
      onOk() {
        window.open('https://mp.weixin.qq.com', '_blank');
      },
      okText: '确定',
      onCancel() {},
      cancelText: '取消'
    });
  };
}

export default WxSetting;
